package com.bawei.seckill.controller;

import com.bawei.common.utils.R;
import com.bawei.seckill.service.SeckillService;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@Controller
public class SeckillController {

    @Autowired
    private SeckillService seckillService;

    @Autowired
    private RedissonClient redissonClient;

    @GetMapping("/get")
    @ResponseBody
    public R get(){
        RLock lock = redissonClient.getLock("666");
        try {
            lock.lock(60, TimeUnit.SECONDS);
            seckillService.uploadSeckillSkuLatestDays();
            lock.unlock();
        } finally {

        }
        return  R.ok();
    }
}
